/**
 * 
 */
package org.wangh.csv.def;

import java.util.ArrayList;
import java.util.List;

/**
 * @author he
 *
 */
public class Row {
	
	private List<CSVCell> listOfCell;
	
	private boolean isHeader;

	public Row(List<CSVCell> listOfCell) {
		this.listOfCell = listOfCell;
	}

	public Row() {
		this.listOfCell = new ArrayList<CSVCell>();
	}
	
	public void setRow(List<CSVCell> listOfCell){
		this.listOfCell = listOfCell;
	}
	
	public List<CSVCell> getElementList(){
		return this.listOfCell;
	}
	
	public CSVCell[] getElements(){
		return (CSVCell[]) this.listOfCell.toArray();
	}
	
	public boolean isValid(){
		return this.listOfCell == null || this.listOfCell.isEmpty();
	}
	
	public boolean isHeader(){
		return isHeader;
	}
	
	public void setIsHeader(boolean value){
		this.isHeader = value;
	}
	
	public void add(CSVCell cell){
		if(this.listOfCell == null){
			listOfCell = new ArrayList<CSVCell>();
		}
		listOfCell.add(cell);
	}
	
	public CSVCell get(int index){
		return listOfCell.get(index);
	}
	
	public CSVCell get(String name){
		for(CSVCell cell : listOfCell){
			if(cell.getIndexName().equals(name)){
				return cell;
			}
		}
		return null;
	}
	
	public int getSize(){
		return listOfCell.size();
	}
}
